# Compiler settings
CXX = g++
CXXFLAGS = -std=c++14 -Iinclude

# Phony targets
.PHONY: all clean run B C D E F plot report setup

# Default target
all: setup B C D E F plot report

HEADS = include/Bezier.hpp include/Interp.hpp

# OS Check
ifeq ($(OS),Windows_NT)
    TARGET_EXT = .exe
else
    TARGET_EXT =
endif

# Setup target to create directories
setup:
	mkdir -p images
	mkdir -p output

# Rule for B
B: src/B.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o B$(TARGET_EXT) src/B.cpp
	./B$(TARGET_EXT) > output/output_B.txt

# Rule for C
C: src/C.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o C$(TARGET_EXT) src/C.cpp
	./C$(TARGET_EXT) > output/output_C.txt

# Rule for D
D: src/D.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o D$(TARGET_EXT) src/D.cpp
	./D$(TARGET_EXT) > output/output_D.txt

# Rule for E
E: src/E.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o E$(TARGET_EXT) src/E.cpp
	./E$(TARGET_EXT) > output/output_E.txt

# Rule for F
F: src/F.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o F$(TARGET_EXT) src/F.cpp
	./F$(TARGET_EXT) > output/output_F.txt

# Rule for plot
plot:
	python src/plot.py

# Compile the report and get index.html
report:
	xelatex report.tex
	xelatex report.tex
	doxygen Doxyfile

# Run all B, C, D, E, F in sequence
run: setup B C D E F

# Clean target
clean:
	rm -f *.o *.exe *.aux *.log *.gz *.pdf *.out *.txt index.html
	rm -rf Doxydocs images output